package client;

import handler.RequestHandler;

import java.util.HashMap;

import syncPoolExecutor.SyncPoolManager;

import builder.RequestBuilder;
import Interceptor.RequestInterceptor;
import Interceptor.RequestInterceptor2;
import Interceptor.RequestInterceptorActionInterface;
import Interceptor.ResponseInterceptor;
import Interceptor.ResponseInterceptor2;
import Interceptor.ResponseInterceptorActionInterface;
import SyncPools.CallBack;
import SyncPools.HttpLifeCycleInterface;
import SyncPools.ThreadPoolExeService;
import SyncPools.URLConfig;

public class MHttpClient {
	RequestInterceptor2 requestInterceptor;
	ResponseInterceptor2 responseInterceptor;

	public MHttpClient addRequestInterceptor(RequestInterceptorActionInterface requestInterceptor) {
		if (this.requestInterceptor == null)
			this.requestInterceptor =new RequestInterceptor2(requestInterceptor); 
 
		else
		this.requestInterceptor = new RequestInterceptor2(requestInterceptor).setRequestInterceptor2(this.requestInterceptor);
 
		
		return this;
	}

	public MHttpClient addResponseInterceptor(
			ResponseInterceptorActionInterface responseInterceptor) {
	 
		
		if (this.responseInterceptor == null)
			this.responseInterceptor =new ResponseInterceptor2(responseInterceptor); 
 
		else
		this.responseInterceptor = new ResponseInterceptor2(responseInterceptor).setResponseInterceptor2(this.responseInterceptor);

		
		
		
		return this;
	}

	public RequestHandler newRequest(URLConfig config,
			HttpLifeCycleInterface httpLifeCycleInterface) {

		CallBack callBack = new CallBack(config, httpLifeCycleInterface);

		RequestHandler requstManager = callBack.getRequstManager();

		requstManager.addRequestInterceptor(this.requestInterceptor);
		
		requstManager.addResponseInterceptor(responseInterceptor);
		
		//ThreadPoolExeService.getInstance().exece(callBack);
		 SyncPoolManager.builder(4).addWorkTasK(callBack);
 		
		return requstManager;
	}

}
